<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/19
 * Time: 9:33
 */

namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;

class Second extends Controller
{
     public function page(){

         $id = 1;
         $count = 6;
         $row = Db::table('news')->field('count(*) as total')->find();
         $num = ceil($row['total']/$count);
         $start=($id-1)*$count;
         $shuju = Db::table('news')->limit($start,$count)->select();
         $last = ($id==1)?1:($id-1);
         $next = ($id==$num)?$num:($id+1);
         $str = "";
         $str.="<a data-id='1'>首页</a>";
         $str.="<a data-id='$last'>上一页</a>";
         $str.="<a data-id='$next'>下一页</a>";
         $str.="<a data-id='$num'>尾页</a>";
         $this->assign('str',$str);
         return $this->fetch('Second/second');
     }

     public function ajax(){
         $request = Request();
         $d = $request->param('id');
         $id = isset($d)?$d:1;
         $count = 6;
         $row = Db::table('news')->field('count(*) as total')->find();
         $num = ceil($row['total']/$count);
         $start=($id-1)*$count;
         $shuju = Db::table('news')->limit($start,$count)->select();
         $last = ($id==1)?1:($id-1);
         $next = ($id==$num)?$num:($id+1);
         $str = "";
         $str.="<a data-id='1'>首页</a>";
         $str.="<a data-id='$last'>上一页</a>";
         $str.="<a data-id='$next'>下一页</a>";
         $str.="<a data-id='$num'>尾页</a>";
         echo json_encode(['shuju'=>$shuju,'str'=>$str]);
     }
}